Micron Document
🎖️GitЯра🎖️


Displaying Raw • Download

core/common/src/commonTest/kotlin/org/meshtastic/core/common/util/ExceptionsTest.kt 5235b8fc51eb5f46d453effb2deec00bcc6abdbb (5235b8fc) Text, 4.52 KB

T8b949e/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
Tff7b72package T7ee787org.meshtastic.core.common.util

Tff7b72import T7ee787kotlinx.coroutines.test.runTest
Tff7b72import T7ee787kotlin.test.AfterTest
Tff7b72import T7ee787kotlin.test.Test
Tff7b72import T7ee787kotlin.test.assertEquals
Tff7b72import T7ee787kotlin.test.assertFalse
Tff7b72import T7ee787kotlin.test.assertNull
Tff7b72import T7ee787kotlin.test.assertTrue

Tff7b72class T56d364ExceptionsTest Tb4b4b4{

Tf0883e@AfterTest
Tff7b72fun Td2a8fftearDownTb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3ExceptionsTb4b4b4.Te6edf3reporter Tff7b72= Tff7b72null
Tb4b4b4}

T8b949e// ---------- Exceptions.report ----------

Tf0883e@Test
Tff7b72fun Td2a8ff`report invokes configured reporter with all arguments`Tb4b4b4(Tb4b4b4) Tb4b4b4{
Tff7b72var Te6edf3capturedTb4b4b4: Te6edf3TripleTff7b72<Te6edf3ThrowableTb4b4b4, Tffa657String?Tb4b4b4, Tffa657String?Tff7b72>Tff7b72? Tff7b72= Tff7b72null
Te6edf3ExceptionsTb4b4b4.Te6edf3reporter Tff7b72= Tb4b4b4{ Te6edf3exTb4b4b4, Te6edf3tagTb4b4b4, Te6edf3msg Tff7b72-Tff7b72> Te6edf3captured Tff7b72= Te6edf3TripleTb4b4b4(Te6edf3exTb4b4b4, Te6edf3tagTb4b4b4, Te6edf3msgTb4b4b4) Tb4b4b4}

Tff7b72val Te6edf3error Tff7b72= Te6edf3RuntimeExceptionTb4b4b4(Ta5d6ff"Ta5d6ffboomTa5d6ff"Tb4b4b4)
Te6edf3ExceptionsTb4b4b4.Te6edf3reportTb4b4b4(Te6edf3errorTb4b4b4, Te6edf3tag Tff7b72= Ta5d6ff"Ta5d6ffMyTagTa5d6ff"Tb4b4b4, Te6edf3message Tff7b72= Ta5d6ff"Ta5d6ffcontextTa5d6ff"Tb4b4b4)

Te6edf3assertEqualsTb4b4b4(Te6edf3errorTb4b4b4, Te6edf3capturedTff7b72?.Te6edf3firstTb4b4b4)
Te6edf3assertEqualsTb4b4b4(Ta5d6ff"Ta5d6ffMyTagTa5d6ff"Tb4b4b4, Te6edf3capturedTff7b72?.Te6edf3secondTb4b4b4)
Te6edf3assertEqualsTb4b4b4(Ta5d6ff"Ta5d6ffcontextTa5d6ff"Tb4b4b4, Te6edf3capturedTff7b72?.Te6edf3thirdTb4b4b4)
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ff`report works with null tag and message`Tb4b4b4(Tb4b4b4) Tb4b4b4{
Tff7b72var Te6edf3capturedTb4b4b4: Te6edf3TripleTff7b72<Te6edf3ThrowableTb4b4b4, Tffa657String?Tb4b4b4, Tffa657String?Tff7b72>Tff7b72? Tff7b72= Tff7b72null
Te6edf3ExceptionsTb4b4b4.Te6edf3reporter Tff7b72= Tb4b4b4{ Te6edf3exTb4b4b4, Te6edf3tagTb4b4b4, Te6edf3msg Tff7b72-Tff7b72> Te6edf3captured Tff7b72= Te6edf3TripleTb4b4b4(Te6edf3exTb4b4b4, Te6edf3tagTb4b4b4, Te6edf3msgTb4b4b4) Tb4b4b4}

Te6edf3ExceptionsTb4b4b4.Te6edf3reportTb4b4b4(Te6edf3RuntimeExceptionTb4b4b4(Ta5d6ff"Ta5d6ffxTa5d6ff"Tb4b4b4)Tb4b4b4)

Te6edf3assertNullTb4b4b4(Te6edf3capturedTff7b72?.Te6edf3secondTb4b4b4)
Te6edf3assertNullTb4b4b4(Te6edf3capturedTff7b72?.Te6edf3thirdTb4b4b4)
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ff`report does not crash when no reporter is configured`Tb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3ExceptionsTb4b4b4.Te6edf3reporter Tff7b72= Tff7b72null
T8b949e// Should not throw
Te6edf3ExceptionsTb4b4b4.Te6edf3reportTb4b4b4(Te6edf3RuntimeExceptionTb4b4b4(Ta5d6ff"Ta5d6ffno reporterTa5d6ff"Tb4b4b4)Tb4b4b4)
Tb4b4b4}

T8b949e// ---------- ignoreException ----------

Tf0883e@Test
Tff7b72fun Td2a8ff`ignoreException swallows exceptions from inner block`Tb4b4b4(Tb4b4b4) Tb4b4b4{
Tff7b72var Te6edf3reached Tff7b72= Tff7b72false
Te6edf3ignoreException Tb4b4b4{ Tff7b72throw Te6edf3IllegalStateExceptionTb4b4b4(Ta5d6ff"Ta5d6ffexpectedTa5d6ff"Tb4b4b4) Tb4b4b4}
Te6edf3reached Tff7b72= Tff7b72true
Te6edf3assertTrueTb4b4b4(Te6edf3reachedTb4b4b4)
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ff`ignoreException does not swallow when inner succeeds`Tb4b4b4(Tb4b4b4) Tb4b4b4{
Tff7b72var Te6edf3executed Tff7b72= Tff7b72false
Te6edf3ignoreException Tb4b4b4{ Te6edf3executed Tff7b72= Tff7b72true Tb4b4b4}
Te6edf3assertTrueTb4b4b4(Te6edf3executedTb4b4b4)
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ff`ignoreException silent mode suppresses logging`Tb4b4b4(Tb4b4b4) Tb4b4b4{
T8b949e// Should not crash even in silent mode
Te6edf3ignoreExceptionTb4b4b4(Te6edf3silent Tff7b72= Tff7b72trueTb4b4b4) Tb4b4b4{ Tff7b72throw Te6edf3RuntimeExceptionTb4b4b4(Ta5d6ff"Ta5d6ffsilentTa5d6ff"Tb4b4b4) Tb4b4b4}
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ff`ignoreException non-silent mode logs but does not crash`Tb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3ignoreExceptionTb4b4b4(Te6edf3silent Tff7b72= Tff7b72falseTb4b4b4) Tb4b4b4{ Tff7b72throw Te6edf3RuntimeExceptionTb4b4b4(Ta5d6ff"Ta5d6ffloggedTa5d6ff"Tb4b4b4) Tb4b4b4}
Tb4b4b4}

T8b949e// ---------- ignoreExceptionSuspend ----------

Tf0883e@Test
Tff7b72fun Td2a8ff`ignoreExceptionSuspend swallows exceptions`Tb4b4b4(Tb4b4b4) Tff7b72= Te6edf3runTest Tb4b4b4{
Tff7b72var Te6edf3reached Tff7b72= Tff7b72false
Te6edf3ignoreExceptionSuspend Tb4b4b4{ Tff7b72throw Te6edf3IllegalArgumentExceptionTb4b4b4(Ta5d6ff"Ta5d6ffasync boomTa5d6ff"Tb4b4b4) Tb4b4b4}
Te6edf3reached Tff7b72= Tff7b72true
Te6edf3assertTrueTb4b4b4(Te6edf3reachedTb4b4b4)
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ff`ignoreExceptionSuspend silent mode suppresses logging`Tb4b4b4(Tb4b4b4) Tff7b72= Te6edf3runTest Tb4b4b4{
Te6edf3ignoreExceptionSuspendTb4b4b4(Te6edf3silent Tff7b72= Tff7b72trueTb4b4b4) Tb4b4b4{ Tff7b72throw Te6edf3RuntimeExceptionTb4b4b4(Ta5d6ff"Ta5d6ffsilent asyncTa5d6ff"Tb4b4b4) Tb4b4b4}
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ff`ignoreExceptionSuspend executes block normally when no exception`Tb4b4b4(Tb4b4b4) Tff7b72= Te6edf3runTest Tb4b4b4{
Tff7b72var Te6edf3executed Tff7b72= Tff7b72false
Te6edf3ignoreExceptionSuspend Tb4b4b4{ Te6edf3executed Tff7b72= Tff7b72true Tb4b4b4}
Te6edf3assertTrueTb4b4b4(Te6edf3executedTb4b4b4)
Tb4b4b4}

T8b949e// ---------- exceptionReporter ----------

Tf0883e@Test
Tff7b72fun Td2a8ff`exceptionReporter reports exceptions to configured reporter`Tb4b4b4(Tb4b4b4) Tb4b4b4{
Tff7b72var Te6edf3reportCalled Tff7b72= Tff7b72false
Te6edf3ExceptionsTb4b4b4.Te6edf3reporter Tff7b72= Tb4b4b4{ Te6edf3_Tb4b4b4, Te6edf3_Tb4b4b4, Te6edf3_ Tff7b72-Tff7b72> Te6edf3reportCalled Tff7b72= Tff7b72true Tb4b4b4}

Te6edf3exceptionReporter Tb4b4b4{ Tff7b72throw Te6edf3RuntimeExceptionTb4b4b4(Ta5d6ff"Ta5d6ffreportedTa5d6ff"Tb4b4b4) Tb4b4b4}

Te6edf3assertTrueTb4b4b4(Te6edf3reportCalledTb4b4b4)
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ff`exceptionReporter does not invoke reporter when block succeeds`Tb4b4b4(Tb4b4b4) Tb4b4b4{
Tff7b72var Te6edf3reportCalled Tff7b72= Tff7b72false
Te6edf3ExceptionsTb4b4b4.Te6edf3reporter Tff7b72= Tb4b4b4{ Te6edf3_Tb4b4b4, Te6edf3_Tb4b4b4, Te6edf3_ Tff7b72-Tff7b72> Te6edf3reportCalled Tff7b72= Tff7b72true Tb4b4b4}

Te6edf3exceptionReporter Tb4b4b4{
T8b949e// no exception
Tb4b4b4}

Te6edf3assertFalseTb4b4b4(Te6edf3reportCalledTb4b4b4)
Tb4b4b4}

Tf0883e@Test
Tff7b72fun Td2a8ff`exceptionReporter works without configured reporter`Tb4b4b4(Tb4b4b4) Tb4b4b4{
Te6edf3ExceptionsTb4b4b4.Te6edf3reporter Tff7b72= Tff7b72null
T8b949e// Should not crash
Te6edf3exceptionReporter Tb4b4b4{ Tff7b72throw Te6edf3RuntimeExceptionTb4b4b4(Ta5d6ff"Ta5d6ffno reporter configuredTa5d6ff"Tb4b4b4) Tb4b4b4}
Tb4b4b4}
Tb4b4b4}

Served by rngit 1.5.0 - Generated in 0.06s